<template>
  <div class="container">
    <NavBar title="门诊医生站" />
    <van-tabs v-model:active="active" offset-top="46" sticky>
      <van-tab title="待诊">
        <RefreshList
          :minHeight="'calc(100vh - 90px)'"
          :getListApi="getListApi"
          v-model:pageModel="pageModel"
          v-model:dataList="dataList"
        >
          <div class="list-item" v-for="(item, index) in dataList" :key="index">
            {{ item.messageName }}
          </div>
        </RefreshList>
      </van-tab>
      <van-tab title="已诊"></van-tab>
    </van-tabs>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import { getAccessToken } from "@/api/index.js";
import { useRouter } from "vue-router";
import { getDoctorStationList } from "@/api/index.js";
const router = useRouter();
const dataList = ref([]);
const active = ref(0);
const pageModel = reactive({
  page: 1,
  limit: 10,
  total: 0,
  pages: 0,
});

const getAccessTokenData = ref();

onMounted(() => {
  let url = "http://10.150.15.122:3200/index";
  let encodeUrl = encodeURIComponent(url);
  console.log(encodeUrl);
});

const getAccessTokenAction = async () => {
  const res = await getAccessToken(
    "wwa16dcd8c5531a37b",
    "-CQI7QZIZhGZyFrEAf_7pSoillLsq9SJOcNMtB96XyU"
  );
  getAccessTokenData.value = res;
  console.log("res:", res);
};

const handleToIntegralPage = () => {
  //router.push("/integral");
};

const setTotal = 11; // 设置列表总记录数
let dbList = []; // 通过循环向数组插入测试数据
for (let i = 0; i < setTotal; i++) {
  dbList.push({
    id: i + 1,
    messageName: "长图片" + (i + 1),
    createdAt: "2021-07-27 17:06:19",
    createdByDeptName: "百色",
    url: "http://vue.tuokecat.com/cdn/h5/newslist.jpg",
  });
}

/**
 * 模拟通过api获取第几页的数据
 * @param {每页多少条记录} limit
 * @param {第几页} page
 */
const getListApi = async (limit, page) => {
  // let start = limit * (page - 1);
  // let end = limit * page;
  // let tempList = dbList.slice(start, end);
  // console.log(pageModel, tempList, `获取第${page}页数据列表`);
  // const result = {
  //   code: 200,
  //   message: "success",
  //   data: {
  //     docs: tempList,
  //     page: page,
  //     limit: limit,
  //     total: setTotal,
  //     pages: Math.ceil(setTotal / 10),
  //   },
  // };

  // const sleep = (time) => {
  //   return new Promise((resolve) => setTimeout(resolve, time));
  // };
  await getDoctorStationList();
  // return new Promise((resolve) => resolve(result));
};
</script>

<style lang="less" scoped>
.container {
  min-height: 100vh;
  background-color: #f8f8f8;
  .list-item {
    width: 100%;
    height: 80px;
  }
}
</style>
